# Created with PyCharm.
# Coding UTF-8
# @Version Python 3.8

# @author GeekChunky
# @Email caiyoupeng00@outlook.com

# @Date 2021/12/11
# @CreatTime 15:56


'''
Documentation comments:

'''

# Now Write Down Your Python Code in Editor...
# Wish You Happy Everyday !
# -*- coding: UTF-8 -*-
from time import sleep
from selenium import webdriver
from msedge.selenium_tools import Edge, EdgeOptions

driver_url = r"C:\Users\caiyo\AppData\Local\Programs\Python\Python38\BroswerDriver\msedgedriver.exe"

options = EdgeOptions()
# 使用谷歌内核
options.use_chromium = True
# 浏览器可执行文件绝对路径
options.binary_location = r"C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe"
# 浏览器不提供可视化页面. linux下如果系统不支持可视化不加这条会启动失败
options.add_argument("--headless")
# 谷歌文档提到需要加上这个属性来规避bug
# options.add_argument("disable-gpu")
# 隐私模式
# options.add_argument("-inprivate")
# 如果上文2步设置了环境变量可不传executable_path，port：驱动默认端口号，可不传
# browser = Edge(executable_path=driver_url, port=9515, options=options)
driver = Edge(executable_path=driver_url, options=options)
driver.get("http://www.baidu.com")
# 保存截图到项目相对路径
driver.save_screenshot('baidu.png')
print('done')
driver.quit()

# Chrome静默运行
# from selenium import webdriver
# chrome_options = webdriver.ChromeOptions()
# chrome_options.add_argument('--headless')
# driver = webdriver.Chrome(chrome_options=chrome_options)
# driver.get('http://baidu.com')#打开百度首页，可以更换引号内的网址实现打开任一网址
# print(driver.title)#在编辑器的终端可以看到网站的标题打印出来
# driver.save_screenshot('baidu.png')
# driver.quit()#关闭Chrome浏览器，如果不写这句话浏览器就会停留在百度首页在后台运行不会关闭浏览器
